package net.cloudsun.graph.puzzle;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;

import java.io.File;
import java.util.List;
import java.util.Random;

/**
 * javafx
 *
 * @author Ryan
 * @since 1.0
 */
public class MainApplication extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        // 先造一个状态作为初态
        JigsawGraph jigsawGraph = new JigsawGraph(new File("jigsaw-vertices.dat"));

        int length = jigsawGraph.getVertices().length;
        int index = new Random().nextInt(length);
        JigsawState tofind = jigsawGraph.getVertices()[index];
        List<JigsawState> path = jigsawGraph.bfs(JigsawGraph.FINAL_STATE_INDEX, index);


        final ImageView[] images = new JigsawStateImage(tofind).toImage();

        final Group root = new Group(images);
        root.setAutoSizeChildren(true);
        Scene scene = new Scene(root, 400, 400);

        primaryStage.setTitle("Welcome to JavaFX!");
        primaryStage.setScene(scene);
        primaryStage.sizeToScene();
        primaryStage.show();
    }
}
